C---------------------------------------------------------
C    TOOLPACK/1    Release: 2.4
C---------------------------------------------------------
C
C  LIBRARY FOR ISTLX
C
C---------------------------------------------------------------------
C
C  INITIALISE THE SCANNER OPERATION
C
      SUBROUTINE INISCN
C
      COMMON /INSTCM/ INSTAT
      INTEGER         INSTAT
 
      COMMON /CURSTC/ ACT, CHAR, ERRORF, FBKUPC, NEWACT, ENDSCR
      INTEGER         ACT, CHAR,FBKUPC, NEWACT
      LOGICAL         ERRORF, ENDSCR
      COMMON /KSTAKC/ IKSTAC, MKSTAC, KSTACK(2500), FTOKEN, TOKEN, KEEPF
      INTEGER         IKSTAC, MKSTAC, KSTACK, FTOKEN, TOKEN
      LOGICAL         KEEPF
      COMMON /CSTAKC/ ICSTAC, MCSTAC, CSTACK(100)
      INTEGER         ICSTAC, MCSTAC, CSTACK
      COMMON /NESTCM/ NSTELS
      INTEGER         NSTELS
      INTEGER         SDNCPW, SDNCPS
      PARAMETER (SDNCPW=31, SDNCPS=128)
      COMMON /CHRBFC/ ICHAR, CBFSIZ, CBFEND, MCHAR, CHRBUF(1603)
      INTEGER         ICHAR, CBFSIZ, CBFEND, MCHAR, CHRBUF
      COMMON /CHICOM/ ERRCHI, EOLCHI, EOICHI, EOFCHI
      INTEGER         ERRCHI, EOLCHI, EOICHI, EOFCHI
      INTEGER ACTSIZ
      PARAMETER (ACTSIZ = 2050)
      COMMON /AKSCM2/ AKSHN2(ACTSIZ)
      INTEGER         AKSHN2
      COMMON /AKSCM1/ AKSHN1(ACTSIZ)
      INTEGER         AKSHN1
      COMMON /XCDONE/ AA1(ACTSIZ),AA2(ACTSIZ),AA3(ACTSIZ),AA4(ACTSIZ),
     +                AA5(ACTSIZ)
      INTEGER         AA1,AA2,AA3,AA4,AA5
 
      INTEGER I, ZIAND, ZLRS, MASK1, MASK2
      PARAMETER(MASK1=4095, MASK2=63)
 
      SAVE
C
      INSTAT=-1
      ACT = 1
      ERRORF = .FALSE.
      ENDSCR = .FALSE.
      IKSTAC = 1
      KSTACK(1) = 0
      FTOKEN = 1
      TOKEN = 1
      KEEPF = .FALSE.
      ICSTAC = 1
      CSTACK(1) = 0
      NSTELS = 0
C
C  SET THE INTERNAL CHARACTERS REQUIRED TO INDICATE ERROR, END-OF-LINE,
C  END-OF-INPUT AND END-OF-FILE.
C
      ERRCHI = SDNCPS + 1
      EOLCHI = SDNCPS + 2
      EOICHI = SDNCPS + 3
      EOFCHI = SDNCPS + 4
C
C  SET UP THE CHARACTER BUFFER USED BY THE SCANNER
C
      CBFEND = MCHAR - 1
      CBFSIZ = MCHAR - 2
 
      CHRBUF(MCHAR) = EOICHI
      ICHAR         = 1
      CHRBUF(1)     = EOICHI
      CHAR          = EOICHI
C
C  AA1 = AKTYPE
C  AA2 = AKCSET
C  AA3 = CALLAK
C  AA4 = VALLOC
C  AA5 = NEXTAK
C
      DO 10 I = 1, ACTSIZ
        AA1(I) = ZIAND(ZLRS(AKSHN1(I), 24), MASK2)
        AA2(I) = ZIAND(ZLRS(AKSHN1(I), 12), MASK1)
        AA3(I) = ZIAND(AKSHN1(I), MASK1)
        AA4(I) = ZIAND(ZLRS(AKSHN2(I), 12), MASK1)
        AA5(I) = ZIAND(AKSHN2(I), MASK1)
   10 CONTINUE
 
      END
C---------------------------------------------------------------------
C
      SUBROUTINE ADVANC(I,ARRAY,CS)
 
      INTEGER         SDNCPW, SDNCPS
      PARAMETER (SDNCPW=31, SDNCPS=128)
 
      INTEGER I, ARRAY(*), CS, TEMP
      LOGICAL IN
      SAVE
C
   10 CONTINUE
        TEMP = ARRAY(I)
        IF(TEMP .LT. SDNCPS) TEMP = TEMP + 1
        IF(.NOT.IN(TEMP, CS)) RETURN
        I = I + 1
      GO TO 10
C
      END
C------------------------------------------------------------------------
C
      LOGICAL FUNCTION IN(CHAR, CS)
      INTEGER CHAR, CS
C
      INTEGER BTVSIZ
      PARAMETER (BTVSIZ = 72)
      COMMON /BTVRCM/ BTVCTR(5, BTVSIZ)
      INTEGER         BTVCTR
      INTEGER         SDNCPW, SDNCPS
      PARAMETER (SDNCPW=31, SDNCPS=128)
C
      INTEGER IBIT, ZLRS, ZIAND, IWORD
      SAVE /BTVRCM/
      EXTERNAL ZIAND,ZLRS
C
      IF(CHAR .LE. SDNCPW) THEN
        IWORD = 1
        IBIT = 31 - CHAR
      ELSE IF(CHAR .LE. SDNCPW*2) THEN
        IWORD = 2
        IBIT = 31 - CHAR + SDNCPW
      ELSE IF(CHAR .LE. SDNCPW*3) THEN
        IWORD = 3
        IBIT = 31 - CHAR + (SDNCPW*2)
      ELSE IF(CHAR .LE. SDNCPW*4) THEN
        IWORD = 4
        IBIT = 31 - CHAR + (SDNCPW*3)
      ELSE
        IWORD = 5
        IBIT = 31 - CHAR + (SDNCPW*4)
      ENDIF
      IN=ZIAND(ZLRS(BTVCTR(IWORD, CS), IBIT), 1).NE.0
C
      END
